package io.ouka.jvm.hotspot.selfread.util;

import java.io.*;
import java.util.Arrays;

/**
 * @author Ouka
 */
public class FileReader {
//    "/home/ouka/code/java/study_jvm/jvm/target/classes/io/ouka/jvm/Test.class"
    public static byte[] readClass(String classPath) throws IOException {
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(classPath));
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);

        System.out.println("Available bytes:" + in.available());

        byte[] temp = new byte[1024];
        int size = 0;
        while ((size = in.read(temp)) != -1) {
            out.write(temp, 0, size);
        }
        in.close();

        return out.toByteArray();
    }

}
